/**
 * Created by GZB on 2017/9/11.
 */

//扩展datagrid编辑器类型（添加laydate时间控件）
$.extend($.fn.datagrid.defaults.editors, {
    laydate: {
        init: function(container, options){
            options = $.extend({},{className:'easyuiEditText',label:'',validateProxy:'',length:0}, options);
            var input = $('<input type="text" onclick="laydate({position:\'fixed\'})" class="laydate-icon '+
                options.className+'" quick-config="label:'+
                options.label+', validateProxy:'+
                options.validateProxy+', length: '+
                options.length+'" style="width:80%;border-radius:0;border-color:#ccc">').appendTo(container);
            return input;
        },
        setValue: function(target, value){
            $(target).val(value);
        },
        getValue: function(target){
            return $(target).val();
        },
    }
});

/** quickJs框架验证  */
$.extend($.fn.datagrid.defaults.editors, {
    quickTextValidate: {
        init: function(container, options){
            options = $.extend({},{className:'easyuiEditText',label:'',validateProxy:'',length:0}, options);
            var input = $('<input class="'+
                options.className+'" style="height:22px;width:100%;border-radius:0" quick-config="label:'+
                options.label +', validateProxy:'+
                options.validateProxy +', length: '+
                options.length +'" />').appendTo(container);
            return input;
        },
        setValue: function(target, value){
            $(target).val(value);
},
        getValue: function(target){
            return $(target).val();
        },
    }
});

$.extend($.fn.datagrid.defaults.editors, {
    quickSelectValidate: {
        init: function(container, options){
            options = $.extend({},{className:'easyuiEditText',label:'',validateProxy:''}, options);
            var select = $('<select class="'+
                options.className+'" style="height:24px;width:100%;border-radius:0" quick-config="label:'+
                options.label +', validateProxy:'+
                options.validateProxy +'">');
            select.createOptions(options.data,{textField : options.textField , valueField : options.valueField});
            select.appendTo(container);
            return select;
        },
        setValue: function(target, value){
            //保存初始值
            var $target = $(target);
            if(StringUtils.isEmpty($target.attr("firstEditFlag"))){
                $target.attr("firstEditFlag",1);
                $target.attr("editOldValue",value);
            }
            $target.val(value);
        },
        getValue: function(target){
            //非编辑状态下展示的内容
            var result = $(target).children(":selected").text() || $(target).attr("editOldValue");
            if(result != '请选择'){
                return result;
            }
        },
    }
});



